[iOS] Fix ScrollView stale keyboard inset after dismiss#56189
[iOS] Fix ScrollView stale keyboard inset after dismiss#56189Miyou wants to merge 3 commits intofacebook:mainfrom
Conversation
|
Hi @Miyou! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
| static inline UIEdgeInsets RCTEffectiveContentInset(UIScrollView *scrollView) | ||
| { | ||
| if (@available(iOS 11.0, *)) { | ||
| if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, scrollView.adjustedContentInset)) { |
There was a problem hiding this comment.
@Miyou
Would it be safer/simpler to always prefer adjustedContentInset on iOS 11+ (without the != .zero guard), since that is UIKit’s effective geometry even when it happens to be zero?
As written, zero adjusted values fall back to contentInset, which may reintroduce mismatch in some transition states.
There was a problem hiding this comment.
Good point. I updated it to always prefer adjustedContentInset on iOS 11+ rather than falling back to contentInset when the adjusted inset is .zero.
I re-verified the original repro after the change, and the stale bottom padding after keyboard dismissal still no longer reproduces.
There was a problem hiding this comment.
@Miyou PR seems fine to me now! lets wait for other reviewers
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
Summary:
This fixes an iOS
ScrollViewbug where usingautomaticallyAdjustKeyboardInsetstogether withcontentInsetAdjustmentBehavior="automatic"can leave a stale bottom gap after the keyboard is dismissed. The extra space is not cleared until the user scrolls again.The underlying issue is that the keyboard dismissal path can call
scrollToOffsetwith an offset that needs to be clamped against the new inset-adjusted bounds, but the current code checks for an unchangedcontentOffsetbefore that clamping happens. WhenadjustedContentInsetshrinks after the keyboard closes, the numeric offset can compare equal while still being outside the valid range, sosetContentOffsetis skipped and the stale gap remains visible.This change:
adjustedContentInsetwhen available) when computing the valid scroll rangeautomaticallyAdjustKeyboardInsets+contentInsetAdjustmentBehavior="automatic"combinationChangelog:
[IOS] [FIXED] Fix
ScrollViewleaving stale bottom inset after keyboard dismissal when usingautomaticallyAdjustKeyboardInsetswith automatic content inset adjustmentTest Plan:
automaticallyAdjustKeyboardInsetscontentInsetAdjustmentBehavior="automatic"TextInputnear the bottom of the scroll viewScrollViewKeyboardInsetsIOSExample.jsthat reproduces this exact prop combination for upstream verification.Build/validation details:
npx expo prebuild --platform ios --no-installnpx pod-install iosxcodebuild -workspace ios/scrollviewautomaticallyadjustkeyboardinsetsbug.xcworkspace -scheme scrollviewautomaticallyadjustkeyboardinsetsbug -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16 Pro' build